import { Selector } from '@ngxs/store';
import { SystemState, SystemStateModel } from './system.state';
import * as _ from 'lodash';

export class SystemSelector {
  @Selector([SystemState])
  static tempData({tempData}: SystemStateModel) {
    return tempData;
  }

  @Selector([SystemState])
  static user({user}: SystemStateModel) {
    return user;
  }

  @Selector([SystemState])
  static authorities({user}: SystemStateModel) {
    return _.map(user?.authorities || [], s => s.authority);
  }

  @Selector([SystemState])
  static token({token}: SystemStateModel) {
    return token;
  }

  @Selector([SystemState])
  static username({user}: SystemStateModel) {
    return user.name || user.username;
  }

  @Selector([SystemState])
  static dictionary({dictionary}: SystemStateModel) {
    return dictionary;
  }
}
